//
//  BCUserInfoBaseCell.m
//  GSBlockChain
//
//  Created by guoshikeji_a on 2018/11/27.
//  Copyright © 2018 guoshikeji. All rights reserved.
//

#import "BCUserInfoBaseCell.h"

@implementation BCUserInfoBaseCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self setupBaseViews];
    }
    return self;
}

- (QMUILabel *)detailLabel {
    if (!_detailLabel) {
        _detailLabel = [QMUILabel new];
        _detailLabel.textColor = [UIColor qmui_colorWithHexString:@"#666666"];
        _detailLabel.font = [UIFont systemFontOfSize:15 weight:UIFontWeightRegular];
        _detailLabel.adjustsFontSizeToFitWidth = true;
        _detailLabel.menuItemTitleForCopyAction = BCLocalizedKey(@"general_copy");
        [self.contentView addSubview:_detailLabel];
        [_detailLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.mas_equalTo(self.contentView).offset(-15.0);
            make.centerY.mas_equalTo(self.contentView);
            make.width.mas_lessThanOrEqualTo(self.contentView).multipliedBy(.5).offset(-15.0);
        }];
        //
        _detailLabel.didCopyBlock = ^(QMUILabel *label, NSString *stringCopied) {
            [[UIPasteboard generalPasteboard] setString:stringCopied];
        };
    }
    return _detailLabel;
}


- (void)setupBaseViews {
    self.titleLabel = [UILabel new];
    self.titleLabel.textColor = [UIColor qmui_colorWithHexString:@"#333333"];
    self.titleLabel.font = [UIFont systemFontOfSize:16 weight:UIFontWeightRegular];
    self.titleLabel.adjustsFontSizeToFitWidth = true;
    [self.contentView addSubview:self.titleLabel];
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.contentView);
        make.left.mas_equalTo(self.contentView).offset(15.0);
        make.width.mas_lessThanOrEqualTo(self.contentView).multipliedBy(.5).offset(-15.0);
    }];
    
    //
    [self addSubview:self.separatorLine];
    [self.separatorLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self).offset(10.0);
        make.right.mas_equalTo(self).offset(-10.0);
        make.bottom.mas_equalTo(self);
        make.height.mas_equalTo(1.0);
    }];
}

- (void)setCellModel:(BCUserInfoCellModel *)cellModel {
    _cellModel = cellModel;
    //
    NSString *title = cellModel.title;
    if (title.length) {
        self.titleLabel.text = title;
    }else {
        self.titleLabel.text = BCLocalizedKey(cellModel.titleKey);
    }
}

+ (CGFloat)defaultHeight {
    return 50.0f;
}

@end
